package com.roocon.design_pattern.chapter05_guard_suspension;

import java.util.Random;

public class ClientThread extends Thread {

  private final RequestQueue queue;
  private final Random random;
  private final String sendValue;

  public ClientThread(RequestQueue queue, String sendValue) {
    this.queue = queue;
    this.sendValue = sendValue;
    this.random = new Random(System.currentTimeMillis());
  }

  @Override public void run() {

    for (int i = 0; i < 10; i++) {
      System.out.println("ClientJoin -> request " + sendValue);
      queue.putRequest(new Request(sendValue));
      try {
        Thread.sleep(random.nextInt(10_000));
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
  }
}
